<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/tagDeclare.jsp"%>
<%@include file="/headDeclare.jsp"%>
<html>
<head>
	<style type="text/css">
		tr{height: 30px;}
		td{margin: 5px;padding: 5px;}
	</style>
<script type="text/javascript">
	var dialog = frameElement.dialog; //调用页面的dialog对象(ligerui对象)
	$(document).ready(function() {

		$('#userName').focus();
		$.ajaxSetup({
			cache : false,
			async : false
		});

		//异步提交表单
		var options = {
			dataType : 'json',
			beforeSubmit : beforeSubmit,
			success : process
		};
		$("#userForm").submit(function() {
			$(this).ajaxSubmit(options);
			return false;
		});

	});

	//提交前验证
	function beforeSubmit() {
		if (isEmpty($("#userName").val())) {
			$.ligerDialog.alert("用户名不能为空！");
			return false;
		}
		if (isEmpty($("#showName").val())) {
			$.ligerDialog.alert("姓名不能为空！");
			return false;
		}
		return true;
	}

	function process(responseJson) {
		if (responseJson.code == 0) {
			$.ligerDialog.error(responseJson.message);
			return;
		} else {
			$.ligerDialog.question("初始密码为："+responseJson.info);
			window.parent.userForm.submit();
			dialog.close();
		}

	}
</script>
</head>
<body>
	<div>
		<form id="userForm" method="post" action="user/insert.do">
			<table>
				<tr>
					<td>
						<label for="town">用户名：</label>
					</td>
					<td>
						<input type="text" name="userName" id="userName" class="ldText" />
					</td>
				</tr>
				<tr>
					<td>
						<label for="town">姓名：</label>
					</td>
					<td>
						<input type="text" name="showName" id="showName" class="ldText" />
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>